package com.example.mydy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.mydy.R;
import com.example.mydy.model.Invitee;

import java.util.List;

public class InviteeAdapter extends RecyclerView.Adapter<InviteeAdapter.ViewHolder> {
    
    private Context context;
    private List<Invitee> inviteeList;
    
    public InviteeAdapter(Context context, List<Invitee> inviteeList) {
        this.context = context;
        this.inviteeList = inviteeList;
    }
    
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_invitee, parent, false);
        return new ViewHolder(view);
    }
    
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Invitee invitee = inviteeList.get(position);
        
        holder.tvUsername.setText(invitee.getUsername());
        holder.tvNickname.setText(invitee.getNickname());
        holder.tvLevel.setText("级别: " + invitee.getLevel());
        holder.tvRegistrationDate.setText("注册时间: " + invitee.getRegistrationDate());
    }
    
    @Override
    public int getItemCount() {
        return inviteeList.size();
    }
    
    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvUsername;
        TextView tvNickname;
        TextView tvLevel;
        TextView tvRegistrationDate;
        
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvUsername = itemView.findViewById(R.id.tv_username);
            tvNickname = itemView.findViewById(R.id.tv_nickname);
            tvLevel = itemView.findViewById(R.id.tv_level);
            tvRegistrationDate = itemView.findViewById(R.id.tv_registration_date);
        }
    }
} 